package com.hdaccp.hadoop.mr3;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class MyTowNum implements WritableComparable<MyTowNum>{
    private String first ;
    private String seocnd ;

    public String getFirst() {
        return first;
    }

    public void setFirst(String first) {
        this.first = first;
    }

    public String getSeocnd() {
        return seocnd;
    }

    public void setSeocnd(String seocnd) {
        this.seocnd = seocnd;
    }

    public MyTowNum(){
        super() ;
    }

    public MyTowNum(String first,String seocnd){
        this.first = first ;
        this.seocnd = seocnd ;
    }


    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(first);
        dataOutput.writeUTF(seocnd);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
            this.first = dataInput.readUTF() ;
            this.seocnd = dataInput.readUTF() ;
    }

    @Override
    public int compareTo(MyTowNum o) {
        long firstNum = Long.parseLong(first) ;
        long firstNumother = Long.parseLong(o.getFirst() );
        long result = firstNum - firstNumother ;
        if(result==0){
            long second = Long.parseLong(seocnd) ;
            long secondother = Long.parseLong(o.getSeocnd()) ;
            return (int) -(second - secondother) ;
        }
        else{
           return (int) result ;
        }

    }
}
